package edu.uic.cs.i422.s2011.team4;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class SquirrelUIGenerator implements OnClickListener {
	
	private Activity tRef;
	
	int title;
	int help;
	int bread;
	
	/**
	 * All we need is the Activity reference, to construct our widgets
	 * @param t
	 */
	public SquirrelUIGenerator(Activity t) {
		tRef = t;
		title = 0;
		help = 0;
		bread = 0;
	}
	
	/**
	 * This returns our header generated View.
	 * @return
	 */
	public View getHeader() {
		/**
		 *  Load our header template 
		 */
		View header = View.inflate(tRef, R.layout.header, null);
		
		/**
		 * Set the Title
		 */
		TextView t = (TextView) header.findViewById(R.id.headerTitle);
		t.setText(title);
		
		/**
		 * Set the Bread Crumb
		 */
		TextView c = (TextView) header.findViewById(R.id.headerBreadCrumb);
		c.setText(bread);
		
		/**
		 * Fix the help button a little bit
		 */
		ImageButton b = (ImageButton) header.findViewById(R.id.headerHelp);
		b.setBackgroundResource(0);
		b.setOnClickListener(this);
		b.setPadding(0,2,5,2);
        
        /**
         * return the container containing all the views in this class
         * generated.
         */
        return header;
	}
	
	public void setTitle(int i) {
		title = i;
	}
	
	public void setHelp(int i) {
		help = i;
	}
	public void setBreadCrumb(int i) {
		bread = i;
	}

	public void onClick(View v) {
		if (v.getId() == R.id.headerHelp) {
			/**
			 * Make the default toast showing the help text.
			 */
			Toast.makeText(tRef, help, Toast.LENGTH_LONG).show();
		}		
	}
}
